Vim 模板脚本

C:\Program Files\Vim\vimfiles\plugin\autotpl.vim

" vim template
"
if exists("loaded_autotpl")
    finish
endif
let loaded_autotpl = 1

function AutoTpl()
python <<EOF

import vim
import os


if len( vim.current.buffer ) == 1 and not vim.current.buffer[0] :
    ''''''
    filename = os.path.basename(vim.current.buffer.name)
    [filebasename , fileext] = os.path.splitext( filename )
    filetpl = []

    if filebasename == 'sconstruct' :
        filetpl = [
        '#import os',
        '',
        'env = Environment()',
        "env.Program(target=''," ,
        "            source=['']," ,
        "            )"
        ]
        vim.current.buffer[:] = filetpl
        vim.current.window.cursor = (4,20)

    elif fileext == '.py' :
        filetpl = [
        '# !/usr/bin/python' ,
        '# coding : cp936' ,
        '# CopyRight 2012 Adou , All Rights Reserved .' ,
        '' ,
        ''
        ] 
        vim.current.buffer[:] = filetpl
        vim.current.window.cursor = (len(filetpl),0)

    elif fileext == '.rb' :
        filetpl = [
        '# !/usr/bin/ruby' ,
        '# CopyRight 2012 Adou , All Rights Reserved .' ,
        '' ,
        ''
        ] 
        vim.current.buffer[:] = filetpl
        vim.current.window.cursor = (len(filetpl),0)

    elif fileext == '.html' :
        filetpl = [
        '<html>' ,
        '' ,
        '<head>' ,
        '<meta charset="utf-8" />' ,
        '<title>%s</title>' % os.path.basename(vim.current.buffer.name[0:-5]) ,
        '</head>' ,
        '' ,
        '<body>' ,
        '' ,
        '' ,
        '</body>' ,
        '' ,
        '</html>'
        ] 
        vim.current.buffer[:] = filetpl
        vim.command('normal gg=G')
        vim.current.window.cursor = (9,0)

    elif fileext == '.c' :
        filetpl = [
        '#include <stdio.h>' ,
        '' ,
        'int main()' ,
        '{' ,
        '' ,
        '//system("pause") ;' ,
        'return 0 ;' ,
        '}'
        ] 
        vim.current.buffer[:] = filetpl
        vim.command('normal gg=G')
        vim.current.window.cursor = (4,0)

    elif fileext == '.cpp' :
        filetpl = [
        '#include <iostream>' ,
        '' ,
        'using namespace std ;' ,
        '' ,
        'int main()' ,
        '{' ,
        '' ,
        '//system("pause") ;' ,
        'return 0 ;' ,
        '}'
        ] 
        vim.current.buffer[:] = filetpl
        vim.command('normal gg=G')
        vim.current.window.cursor = (6,0)

    elif fileext == '.java' :
        filetpl = [
        'import java.io.* ;' ,
        '' ,
        'class %s' % filebasename ,
        '{' ,
        'public static void main( String args[] )' ,
        '{' ,
        '' ,
        '//System.out.println("Hello,World!") ;' ,
        '}' ,
        '}'
        ] 
        vim.current.buffer[:] = filetpl
        vim.command('normal gg=G')
        vim.current.window.cursor = (6,0)

vim.command(':w')

EOF
endfunction

"command! Atpl call AutoTpl()
nmap <silent> <Leader>tt :call AutoTpl()<CR>

" command! <leader>NN call VimPlayer()
"
"if !hasmapto('<Plug>VimPlayer')
"  nmap <silent><unique> <Leader>pp <Plug>VimPlayer
"endif
"nnoremap <unique><script> <Plug>VimPlayer:VimPlayer<CR>